package com.gxuwz.leave.service;

import com.gxuwz.leave.dao.DepDao;
import com.gxuwz.leave.dao.InstDao;
import com.gxuwz.leave.dao.InstDaoImpl;
import com.gxuwz.leave.entity.Department;
import com.gxuwz.leave.entity.Instructor;
import com.gxuwz.leave.entity.User;

import java.util.List;

public class InstServiceImpl implements InstService{
    private InstDao instDao;
    @Override
    public void addInst(Instructor entity) {
        instDao.insert(entity);
    }

    @Override
    public Instructor findInst(String instID) {
        Instructor inst = new Instructor();
        inst.setInstID(instID);
        List<Instructor> instlist = instDao.query(inst);
        if(instlist==null){
            return inst;
        }else{
            inst = instlist.get(0);
        }
        return inst;
    }

    @Override
    public void deleteInst(String instID) {
        instDao.delete(instID);
    }

    @Override
    public List<Instructor> list(Instructor entity) {
        return instDao.query(entity);
    }

    @Override
    public void editInst(Instructor entity) {
        instDao.update(entity);
    }

    public void setInstDao(InstDao instDao) {
        this.instDao = instDao;
    }

    @Override
    public boolean checkInst(String username, String password) {
        Instructor inst = new Instructor();
        inst.setInstID(username);
        inst.setPassword(password);
        List<Instructor> userList= instDao.query(inst);
        return !userList.isEmpty();
    }
}
